package com.haiqi.modules.map.service;

import com.haiqi.webservice.CYX_APIStub;
import com.haiqi.common.persistence.entity.AlarmMarker;
//import com.haiqi.common.webservicelocal.CYX_APIStub;
import org.apache.axis2.AxisFault;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.rmi.RemoteException;
import java.util.List;
import com.alibaba.fastjson.*;

/**
 * Created by hythzx on 2016/7/28.
 */
@Service
public class MapService {

    @Value("${cyx.server.userName}")
    private String userName;

    @Value("${cyx.server.password}")
    private String password;

    public org.apache.axis2.databinding.ADBBean getObject(
            java.lang.Class type) throws java.lang.Exception {
        return (org.apache.axis2.databinding.ADBBean) type.newInstance();
    }



    public String getAlertList(){
        CYX_APIStub stub = null; //the default implementation should point to the right endpoint
        String res = "";
        try {
            stub = new CYX_APIStub();
            com.haiqi.webservice.CYX_APIStub.GetAlarmListByInputs getAlarmListByInputs64 =
                    (com.haiqi.webservice.CYX_APIStub.GetAlarmListByInputs) getObject(com.haiqi.webservice.CYX_APIStub.GetAlarmListByInputs.class);

            // TODO : Fill in the getAlarmListByInputs64 here
            com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE validSoapHeader65 = (com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader65.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader65 here
            getAlarmListByInputs64.setPageindex(1);
            getAlarmListByInputs64.setPagesize(0);
            CYX_APIStub.GetAlarmListByInputsResponse alarmListByInputs = stub.getAlarmListByInputs(getAlarmListByInputs64,validSoapHeader65);
            res = alarmListByInputs.getGetAlarmListByInputsResult();
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 获取一条VTS信息
     * @param guid VTS告警信息ID
     * @return
     */
    public String getOneAlarmMarker(String guid){
        CYX_APIStub stub = null; //the default implementation should point to the right endpoint
        String res = "";
        try {
            stub = new CYX_APIStub();
            com.haiqi.webservice.CYX_APIStub.FindOneAlarmMarker findOneAlarmMarker =
                    (com.haiqi.webservice.CYX_APIStub.FindOneAlarmMarker) getObject(com.haiqi.webservice.CYX_APIStub.FindOneAlarmMarker.class);

            // TODO : Fill in the getAlarmListByInputs64 here
            com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE validSoapHeader65 = (com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader65.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader65 here
            findOneAlarmMarker.setGuid(guid);
            CYX_APIStub.FindOneAlarmMarkerResponse findOneAlarmMarkerResponse = stub.findOneAlarmMarker(findOneAlarmMarker,validSoapHeader65);
            res =findOneAlarmMarkerResponse.getFindOneAlarmMarkerResult();
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    public List<AlarmMarker> getAllAlertList(String title,String isValid){
        CYX_APIStub stub = null;
        String res = "";
        List<AlarmMarker> list = null;
        try {
            stub = new CYX_APIStub();
            com.haiqi.webservice.CYX_APIStub.GetAlarmList getAlarmListByInputs65 =
                    (com.haiqi.webservice.CYX_APIStub.GetAlarmList) getObject(com.haiqi.webservice.CYX_APIStub.GetAlarmList.class);

            // TODO : Fill in the getAlarmListByInputs64 here
            com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE validSoapHeader65 = (com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader65.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader65 here
            getAlarmListByInputs65.setTitle(title);
            getAlarmListByInputs65.setIsValid(isValid);
            getAlarmListByInputs65.setPageindex(1);
            getAlarmListByInputs65.setPagesize(0);
            CYX_APIStub.GetAlarmListResponse getAlarmList = stub.getAlarmList(getAlarmListByInputs65,validSoapHeader65);
            res = getAlarmList.getGetAlarmListResult();
            //System.out.println(res);
            List<AlarmMarker> alarmMarkers = JSON.parseArray(res, AlarmMarker.class);
            list = JSON.parseArray(res,AlarmMarker.class);
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean dropAlarmMarker(String guid){
        CYX_APIStub stub = null;
        boolean res=false;
        try{
            stub = new CYX_APIStub();
            com.haiqi.webservice.CYX_APIStub.DropAlarmMarker dropAlarmMarker7 =
                    (com.haiqi.webservice.CYX_APIStub.DropAlarmMarker)getObject(com.haiqi.webservice.CYX_APIStub.DropAlarmMarker.class);
            // TODO : Fill in the dropAlarmMarker7 here
            com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE validSoapHeader8 =
                    (com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.webservice.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader8.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader8 here
            dropAlarmMarker7.setGuid(guid);
            CYX_APIStub.DropAlarmMarkerResponse dropAlarmMarkerResponse = stub.dropAlarmMarker(dropAlarmMarker7,validSoapHeader8);
            res = dropAlarmMarkerResponse.getDropAlarmMarkerResult();
        }catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;

    }
    public boolean UpdateAlarmMarkerState(String guid,String isValid){
        CYX_APIStub stub = null;
        boolean res=false;
        try{
            stub=new CYX_APIStub();
            CYX_APIStub.SetAlarmMarkerValid setAlarmMarkerValid
                    =(CYX_APIStub.SetAlarmMarkerValid) getObject(CYX_APIStub.SetAlarmMarkerValid.class);
            CYX_APIStub.ValidSoapHeaderE validSoapHeader69 =
                    (CYX_APIStub.ValidSoapHeaderE) getObject(CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader69.setValidSoapHeader(validSoapHeader);
            setAlarmMarkerValid.setGuid(guid);
            setAlarmMarkerValid.setIsValid(isValid);
            CYX_APIStub.SetAlarmMarkerValidResponse setAlarmMarkerValidResponse
                    = stub.setAlarmMarkerValid(setAlarmMarkerValid,validSoapHeader69);
            res = setAlarmMarkerValidResponse.getSetAlarmMarkerValidResult();
        }catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }



    /*public String getAlertList(){
        CYX_APIStub stub = null;
        String res = "";
        try {
            stub = new CYX_APIStub();
            com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmListByInputs getAlarmListByInputs64 =
                    (com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmListByInputs) getObject(com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmListByInputs.class);

            // TODO : Fill in the getAlarmListByInputs64 here
            com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE validSoapHeader65 = (com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader65.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader65 here
            getAlarmListByInputs64.setPageindex(1);
            getAlarmListByInputs64.setPagesize(0);
            CYX_APIStub.GetAlarmListByInputsResponse alarmListByInputs = stub.getAlarmListByInputs(getAlarmListByInputs64,validSoapHeader65);
            res = alarmListByInputs.getGetAlarmListByInputsResult();
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    public List<AlarmMarker> getAllAlertList(String title,String isValid){
        CYX_APIStub stub = null;
        String res = "";
        List<AlarmMarker> list = null;
        try {
            stub = new CYX_APIStub();
            com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmList getAlarmListByInputs65 =
                    (com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmList) getObject(com.haiqi.common.webservicelocal.CYX_APIStub.GetAlarmList.class);

            // TODO : Fill in the getAlarmListByInputs64 here
            com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE validSoapHeader65 = (com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader65.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader65 here
            getAlarmListByInputs65.setTitle(title);
            getAlarmListByInputs65.setIsValid(isValid);
            getAlarmListByInputs65.setPageindex(1);
            getAlarmListByInputs65.setPagesize(0);
            CYX_APIStub.GetAlarmListResponse getAlarmList = stub.getAlarmList(getAlarmListByInputs65,validSoapHeader65);
            res = getAlarmList.getGetAlarmListResult();
            List<AlarmMarker> alarmMarkers = JSON.parseArray(res, AlarmMarker.class);
            list = JSON.parseArray(res,AlarmMarker.class);
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean dropAlarmMarker(String guid){
        CYX_APIStub stub = null;
        boolean res=false;
        try{
            stub = new CYX_APIStub();
            com.haiqi.common.webservicelocal.CYX_APIStub.DropAlarmMarker dropAlarmMarker7 =
                    (com.haiqi.common.webservicelocal.CYX_APIStub.DropAlarmMarker)getObject(com.haiqi.common.webservicelocal.CYX_APIStub.DropAlarmMarker.class);
            // TODO : Fill in the dropAlarmMarker7 here
            com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE validSoapHeader8
                    = (com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE) getObject(com.haiqi.common.webservicelocal.CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader8.setValidSoapHeader(validSoapHeader);
            // TODO : Fill in the validSoapHeader8 here
            dropAlarmMarker7.setGuid(guid);
            CYX_APIStub.DropAlarmMarkerResponse dropAlarmMarkerResponse = stub.dropAlarmMarker(dropAlarmMarker7,validSoapHeader8);
            res = dropAlarmMarkerResponse.getDropAlarmMarkerResult();
        }catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }


    public boolean UpdateAlarmMarkerState(String guid,String isValid){
        CYX_APIStub stub = null;
        boolean res=false;
        try{
            stub=new CYX_APIStub();
            CYX_APIStub.SetAlarmMarkerValid setAlarmMarkerValid
                    =(CYX_APIStub.SetAlarmMarkerValid) getObject(CYX_APIStub.SetAlarmMarkerValid.class);
            CYX_APIStub.ValidSoapHeaderE validSoapHeader69 =
                    (CYX_APIStub.ValidSoapHeaderE) getObject(CYX_APIStub.ValidSoapHeaderE.class);
            CYX_APIStub.ValidSoapHeader validSoapHeader = new CYX_APIStub.ValidSoapHeader();
            validSoapHeader.setUserName(userName);
            validSoapHeader.setPassWord(password);
            validSoapHeader69.setValidSoapHeader(validSoapHeader);
            setAlarmMarkerValid.setGuid(guid);
            setAlarmMarkerValid.setIsValid(isValid);
            CYX_APIStub.SetAlarmMarkerValidResponse setAlarmMarkerValidResponse
                    = stub.setAlarmMarkerValid(setAlarmMarkerValid,validSoapHeader69);
            res = setAlarmMarkerValidResponse.getSetAlarmMarkerValidResult();
        }catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  res;
    }*/
}
